package com.nny.alarm.edit.adapter;

import com.nny.alarm.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class LabelAdapter extends BaseAdapter {
	
	private Context mCtx;
	private String[] mData;
	private LayoutInflater mInflater;
	private OnLabelClickedListener mOnLabelClickedListener;
	
	public LabelAdapter(Context ctx)
	{
		mCtx = ctx;
		mInflater = LayoutInflater.from(ctx);
	}
	
	public void update(String[] data)
	{
		mData = data;
		//notifyDataSetChanged();
	}
	
	public void setOnLabelClickedListener(OnLabelClickedListener l)
	{
		mOnLabelClickedListener = l;
	}

	@Override
	public int getCount() {
		if(mData != null)
			return 6; //mData.length;
		return 0;
	}

	@Override
	public Object getItem(int position) {
		if(mData != null)
			return mData[position];
		return null;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView == null)
			convertView = mInflater.inflate(R.layout.gridview_alarm_name, null);
		if(null != convertView)
		{
			String notice = (String)getItem(position);
			TextView tvName = (TextView)convertView.findViewById(R.id.alarm_name_note);

			tvName.setText(notice);
			tvName.setOnClickListener(new MClickListener(position));
		}
		return convertView;
	}
	
	public static interface OnLabelClickedListener
	{
		public void onLabelClickedListener(View v, int id);
	}
	
	private class MClickListener implements View.OnClickListener
	{
		private int mId;
		public MClickListener(int id)
		{
			mId = id;
		}
		
		@Override
		public void onClick(View v) {
			if(null != mOnLabelClickedListener)
			{
				mOnLabelClickedListener.onLabelClickedListener(v, mId);
			}			
		}
		
	}

}
